<!DOCTYPE html>
<script src='../resources/testharness.js'></script>
<script src='../resources/testharnessreport.js'></script>
<script src='resources/shadow-dom.js'></script>
<div id='host1'></div>
<div id='host2'></div>
<div id='host3'></div>
<script>
'use strict';

test(() => {
    let root1 = host1.attachShadow({mode: 'open'});
    assert_not_equals(root1, null, 'Attach open shadow root should succeed.');
    assert_equals(Object.getPrototypeOf(root1), ShadowRoot.prototype,
        'ShadowRoot object should be returned by attachShadow({mode:"open"}).');

    let root2 = host2.attachShadow({mode: 'closed'});
    assert_not_equals(root2, null, 'Attach closed shadow root should succeed.');
    assert_equals(Object.getPrototypeOf(root2), ShadowRoot.prototype,
        'ShadowRoot object should be returned by attachShadow({mode:"closed"}).');

    assert_throws_js(TypeError, () => { host3.attachShadow({mode: 'illegal'}); },
        'Attach shadow root whose mode is neither open nor closed should throw TypeError.');

    assert_throws_dom('NotSupportedError', () => { host1.attachShadow({mode: 'open'}); },
        'Attach shadow on a host which has open shadow root will raise NotSupportedError exception.');
    assert_throws_dom('NotSupportedError', () => { host2.attachShadow({mode: 'open'}); },
        'Attach shadow on a host wich has closed shadow root will raise NotSupportedError exception.');
}, 'Test for Element.attachShadow() with mode parameter.');
</script>
